package cn.jtfadmin.activiti.ueditor.controller;

import cn.jtfadmin.base.lang.common.utils.RequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

/**
 * ueditor config controller
 * @author jtf
 * @version 0.0.2
 */
@RestController
public class UeditorConfigController {

    /**
     * 获取配置
     */
    @RequestMapping(value = "/activiti/ueditor/ueditor.config.js", produces = "text/javascript")
    public void getConfigJs(){
        String requestBasePath = RequestUtils.getRequestBasePath(RequestUtils.getRequest());
        String basePath = requestBasePath+"/activiti/ueditor/";
        HttpServletResponse response =
                RequestUtils.getResponse();
        String content = "(function() {\n" +
                "  var URL = \""+basePath+"\"\n" +
                "  window.UEDITOR_CONFIG = {\n" +
                "    UEDITOR_HOME_URL: URL,\n" +
                "    // 服务器统一请求接口路径\n" +
                "    serverUrl: URL + \"action\",\n" +
                "\n" +
                "    //工具栏上的所有的功能按钮和下拉框，可以在new编辑器的实例时选择自己需要的重新定义\n" +
                "    toolbars: [\n" +
                "      [\n" +
                "        \"fullscreen\",\n" +
                "        \"source\",\n" +
                "        \"|\",\n" +
                "        \"undo\",\n" +
                "        \"redo\",\n" +
                "        \"|\",\n" +
                "        \"bold\",\n" +
                "        \"italic\",\n" +
                "        \"underline\",\n" +
                "        \"fontborder\",\n" +
                "        \"strikethrough\",\n" +
                "        \"superscript\",\n" +
                "        \"subscript\",\n" +
                "        \"removeformat\",\n" +
                "        \"formatmatch\",\n" +
                "        \"autotypeset\",\n" +
                "        \"blockquote\",\n" +
                "        \"pasteplain\",\n" +
                "        \"|\",\n" +
                "        \"forecolor\",\n" +
                "        \"backcolor\",\n" +
                "        \"insertorderedlist\",\n" +
                "        \"insertunorderedlist\",\n" +
                "        \"selectall\",\n" +
                "        \"cleardoc\",\n" +
                "        \"|\",\n" +
                "        \"rowspacingtop\",\n" +
                "        \"rowspacingbottom\",\n" +
                "        \"lineheight\",\n" +
                "        \"|\",\n" +
                "        \"customstyle\",\n" +
                "        \"paragraph\",\n" +
                "        \"fontfamily\",\n" +
                "        \"fontsize\",\n" +
                "        \"|\",\n" +
                "        \"directionalityltr\",\n" +
                "        \"directionalityrtl\",\n" +
                "        \"indent\",\n" +
                "        \"|\",\n" +
                "        \"justifyleft\",\n" +
                "        \"justifycenter\",\n" +
                "        \"justifyright\",\n" +
                "        \"justifyjustify\",\n" +
                "        \"|\",\n" +
                "        \"touppercase\",\n" +
                "        \"tolowercase\",\n" +
                "        \"|\",\n" +
                "        \"link\",\n" +
                "        \"unlink\",\n" +
                "        \"anchor\",\n" +
                "        \"|\",\n" +
                "        \"imagenone\",\n" +
                "        \"imageleft\",\n" +
                "        \"imageright\",\n" +
                "        \"imagecenter\",\n" +
                "        \"|\",\n" +
                "        \"simpleupload\",\n" +
                "        \"insertimage\",\n" +
                "        \"emotion\",\n" +
                "        \"scrawl\",\n" +
                "        \"insertvideo\",\n" +
                "        \"music\",\n" +
                "        \"attachment\",\n" +
                "        \"map\",\n" +
                "        \"gmap\",\n" +
                "        \"insertframe\",\n" +
                "        \"insertcode\",\n" +
                "        \"webapp\",\n" +
                "        \"pagebreak\",\n" +
                "        \"template\",\n" +
                "        \"background\",\n" +
                "        \"|\",\n" +
                "        \"horizontal\",\n" +
                "        \"date\",\n" +
                "        \"time\",\n" +
                "        \"spechars\",\n" +
                "        \"snapscreen\",\n" +
                "        \"wordimage\",\n" +
                "        \"|\",\n" +
                "        \"inserttable\",\n" +
                "        \"deletetable\",\n" +
                "        \"insertparagraphbeforetable\",\n" +
                "        \"insertrow\",\n" +
                "        \"deleterow\",\n" +
                "        \"insertcol\",\n" +
                "        \"deletecol\",\n" +
                "        \"mergecells\",\n" +
                "        \"mergeright\",\n" +
                "        \"mergedown\",\n" +
                "        \"splittocells\",\n" +
                "        \"splittorows\",\n" +
                "        \"splittocols\",\n" +
                "        \"charts\",\n" +
                "        \"|\",\n" +
                "        \"print\",\n" +
                "        \"preview\",\n" +
                "        \"searchreplace\",\n" +
                "        \"drafts\",\n" +
                "        \"help\"\n" +
                "      ]\n" +
                "    ],\n" +
                "  }; \n" +
                "  function getUEBasePath() {\n" +
                "    return URL;\n" +
                "  }\n" +

                "  window.UE = {\n" +
                "    getUEBasePath: getUEBasePath\n" +
                "  };\n" +
                "})();";
        try {
            response.getOutputStream().write(content.getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            //
        }
    }
}
